import path from "path";

module.exports = {
  env: {
    NODE_ENV: '"production"',
  },
  defineConstants: {},
  mini: {},
  h5: {
    entry: {
      package: [path.resolve(__dirname, "..", "src/package/index.ts")],
    },
    webpackChain(chain, webpack) {
      chain
        .entry("package")
        .add(path.resolve(__dirname, "..", "src/package/index.ts"));
      // .add('@tarojs/taro')
      // .add('@tarojs/components')
      // .add('@nutui/nutui-react-taro')
      // .add('@nutui/icons-react-taro');

      chain.output
        .path(path.resolve(__dirname, "..", "target/web/umd"))
        .filename("[name].[contenthash].umd.js") // 为入口文件设置命名规则
        .chunkFilename("[name].[contenthash].umd.js") // 为代码分割后的 chunk 文件设置命名规则
        // .filename('package.umd.js')
        .library("d8dMobile")
        .libraryTarget("umd");

      // 添加 externals 来外挂 react 和 react-dom
      chain.externals({
        react: "React",
        "react-dom": "ReactDOM",
        // "@tarojs/taro": "Taro",
        "@tarojs/components": "TaroComponents",
        "@nutui/nutui-react-taro": "NutuiReactTaro",
        "@nutui/icons-react-taro": "NutuiIconsReactTaro",
      });
    },
  },
};
